//
//  LBBallSelectedAnimationDelegate.m
//  LittleBall
//
//  Created by apple on 11-11-20.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "LBBallSelectedAnimationDelegate.h"
#import "LittleBallPlayViewController.h"

@implementation LBBallSelectedAnimationDelegate

@synthesize m_owner;
@synthesize m_bContinueAnimation;

-(id)initWithBall:(LBBall *)ball owner:(id)owner;
{
    
    if( !(self = [super init]))
    {
        return nil;
    }
    
    m_bContinueAnimation = TRUE;
    m_ball = ball;
    m_owner = owner;
    m_ballNextAlpha = 0.25;
    
    m_ball.m_imageView.alpha = m_ballNextAlpha;
    
    [UIView beginAnimations:nil context:NULL];
    
    [UIView setAnimationDelegate:self];
    
    [UIView setAnimationRepeatCount:1];
    [UIView setAnimationDuration:BALL_SELECTED_CHANGE_SPEED];
    
    [self changeAlpha];
    m_ball.m_imageView.alpha = m_ballNextAlpha;
    
    [UIView commitAnimations];
    
    return self;
}

- (void)animationWillStart:(NSString *)animationID context:(void *)context
{
    // do nothing...    
}

- (void)animationDidStop:(NSString *)animationID finished: (NSNumber *)finished context:(void *)context
{
    if( m_bContinueAnimation )
    {
        [UIView beginAnimations:nil context:NULL];
        
        [UIView setAnimationDelegate:self];
        
        [UIView setAnimationRepeatCount:1];
        [UIView setAnimationDuration:BALL_SELECTED_CHANGE_SPEED];
        
        [self changeAlpha];
        m_ball.m_imageView.alpha = m_ballNextAlpha;
        
        [UIView commitAnimations];
    }
    else
    {
        m_ball.m_imageView.alpha = 1;
    }
}

- (void)changeAlpha
{
    if( 1 == m_ballNextAlpha )
    {
        m_ballNextAlpha = 0.25;
    }
    else
    {
        m_ballNextAlpha = 1;
    }
}

@end
